			// Class for pattern, creates the pattern and code for drawing the opposite poles of it.
			var Pattern = function(setSize,setPatternOdds,creator){
			this.creator = creator;
			this.size = setSize;
			this.patternOdds=setPatternOdds
			this.patternList	= [];
			this.checker = [];
			for(var i=0;i<this.size;i++)
			{
			this.patternList[i]=[];
				for(var j=0;j<this.size;j++)
				{
				this.patternList[i][j] = Math.round( Math.random() * (0.5+this.patternOdds*0.5 ));
				this.checker.push( this.patternList[i][j] );
				}
			}
			
			// Creates rotationarray for any axis: The key is the position from origo and the value is the key equivalient in patternList.
			var makeConverterArray = function(length){
			var rest = length % 2;
			var halfLength = (length-rest)/2;
			var converterArr = [];
				if(rest===1)
				{
					for(var i=0;i<length;i++)
					{
					// The added "o" is a Chrome hack to prevent it from sorting the array
					converterArr["o"+(i - halfLength)] = i;
					}
				}
			    else
				{
				bumpUp = 0;
					for(var i=0;i<length;i++)
					{
					// The added "o" is a Chrome hack to prevent it from sorting the array
					converterArr["o"+(i - halfLength+bumpUp)] = i;
						if(i===halfLength-1)
						{
						bumpUp++;
						}
					}
				}
			return converterArr;
			}
			
			
			var converterArrX = makeConverterArray(this.size);
			var converterArrY = makeConverterArray(this.size);

			//alert(converterArrX+":"+converterArrY);

			var converter = [];
			for (x in converterArrX){
				for (y in converterArrY){
				// The removed "o" is a Chrome hack to prevent it from sorting the array									
				x1 = x.substr(1)*1;
				y1 = y.substr(1)*1;
				converter.push($V(  [x1,y1]  ));
				}
			}

			rot = $M([[0,1],[-1,0]]);			
			this.rotationsCorrect=[];
			this.rotationsCorrectWarned=[];
			//this.rotationsCorrect.push(true);
			this.rotationsCorrectWarned.push(false);
			for (i=0;i<4;i++)
			{
			this.rotationsCorrectWarned.push(false);
				same = true;

				for (x in converter)
				{
					if(this.patternList[ (converterArrX["o"+converter[x].e(1,2)]) ][ (converterArrY["o"+converter[x].e(2,1)]) ] !== this.checker[x])
					{
					same = false;				
					}
 				}
 				for (x in converter)
				{
				converter[x]=rot.x(converter[x]);
 				}
			this.rotationsCorrect.push(same);
			}
						
	
			var drawCode = 	"";	
			// var drawCode = 	"this.negative.draw = function(this.creator.creator.creator.context,rotate, moveX, moveY){";	
			drawCode +=		"this.angle += rotate; ";
			
			drawCode +=		"if(this.angle===360){this.angle=0}; ";
			drawCode +=		"if(this.angle< 0){this.angle=360+rotate}; ";
			drawCode +=		"var checkX = this.stepToX*(this.squareWidth*(this.size+1)+6)+this.shiftX; var checkY = this.stepToY*(this.squareHeight*(this.size+1)+6)+this.shiftY; ";
			drawCode +=		"if(this.x+this.squareWidth*this.size/4<checkX){this.x+=this.squareWidth*this.size/4}else if(this.x-this.squareWidth*this.size/4>checkX) {this.x-=this.squareWidth*this.size/4} else {this.x = checkX}; ";// setX;
			drawCode +=		"if(this.y+this.squareHeight*this.size/4<checkY){this.y+=this.squareHeight*this.size/4}else if(this.y-this.squareHeight*this.size/4>checkY) {this.y-=this.squareHeight*this.size/4} else {this.y = checkY}; ";// setX;
			
			drawCode +=		"var tranX = this.x+this.squareWidth*this.size/2; var tranY=this.y+this.squareHeight*this.size/2; ";
			drawCode +=		"this.creator.creator.creator.context.translate(tranX,tranY); ";
			drawCode += 	"this.creator.creator.creator.context.rotate((this.angle * Math.PI) / 180); "
			drawCode +=		"this.creator.creator.creator.context.translate(-tranX,-tranY); ";
			drawCode += 	"this.creator.creator.creator.context.beginPath(); "
			drawCode +=		"this.creator.creator.creator.context.moveTo(this.x-3,this.y-3); "
			drawCode +=		"this.creator.creator.creator.context.lineTo(this.x+this.squareWidth*this.size+3,this.y-3); "
			drawCode +=		"this.creator.creator.creator.context.lineTo(this.x+this.squareWidth*this.size+3,this.y+this.squareHeight*this.size+3); "
			drawCode +=		"this.creator.creator.creator.context.lineTo(this.x-3,this.y+this.squareHeight*this.size+3); "
			drawCode +=		"this.creator.creator.creator.context.lineTo(this.x-3,this.y-3); "
			drawCode += 	"this.creator.creator.creator.context.fillStyle = this.printColor(); "
			
			var drawCode2 = drawCode;

				for(var i=0;i<this.size;i++)
				{
					for(var j=0;j<this.size;j++)
					{
						if(this.patternList[i][j]===0)
						{
						drawCode +=	"this.creator.creator.creator.context.fillRect("+i+"*this.squareWidth+this.x,"+j+"*this.squareHeight+this.y,this.squareWidth,this.squareHeight); "
						drawCode +=	"this.creator.creator.creator.context.moveTo("+i+"*this.squareWidth+this.x,"+j+"*this.squareHeight+this.y); "
						
							var draw = true;
							if(j>0){
								if(this.patternList[i][j-1]===0)
								{
								draw = false;
								}
							}
							if(draw){
							drawCode +=	"this.creator.creator.creator.context.lineTo(this.squareWidth*"+(i+1)+"+this.x,this.squareHeight*"+j+"+this.y); ";
							}
							else
							{
							drawCode +=	"this.creator.creator.creator.context.moveTo(this.squareWidth*"+(i+1)+"+this.x,this.squareHeight*"+j+"+this.y); ";
							}
							draw = true;
							if(i<(this.size-1)){
								if(this.patternList[i+1][j]===0)
								{
								draw = false;
								}
							}
							if(draw){
							drawCode +=	"this.creator.creator.creator.context.lineTo(this.squareWidth*"+(i+1)+"+this.x,this.squareHeight*"+(j+1)+"+this.y); "
							}
							else
							{
							drawCode +=	"this.creator.creator.creator.context.moveTo(this.squareWidth*"+(i+1)+"+this.x,this.squareHeight*"+(j+1)+"+this.y); "
							}
							draw = true;
							if(j<(this.size-1)){
								if(this.patternList[i][j+1]===0)
								{
								draw = false;
								}
							}
							if(draw){
							drawCode +=	"this.creator.creator.creator.context.lineTo(this.squareWidth*"+i+"+this.x,this.squareHeight*"+(j+1)+"+this.y); "
							}
							else
							{
							drawCode +=	"this.creator.creator.creator.context.moveTo(this.squareWidth*"+i+"+this.x,this.squareHeight*"+(j+1)+"+this.y); "
							}
	
							draw = true;
							if(i>0){
								if(this.patternList[(i-1)][j]===0)
								{
								draw = false;
								}
							}
							if(draw){
							drawCode +=	"this.creator.creator.creator.context.lineTo(this.squareWidth*"+i+"+this.x,this.squareHeight*"+j+"+this.y); "
							}
							else{
							drawCode +=	"this.creator.creator.creator.context.moveTo(this.squareWidth*"+i+"+this.x,this.squareHeight*"+j+"+this.y); "
							}
						}
						else
						{
						drawCode2 +=	"this.creator.creator.creator.context.fillRect("+i+"*this.squareWidth+this.x,"+j+"*this.squareHeight+this.y,this.squareWidth,this.squareHeight); "
						drawCode2 +=	"this.creator.creator.creator.context.moveTo("+i+"*this.squareWidth+this.x,"+j+"*this.squareHeight+this.y); "
		
							var draw = true;
							if(j>0){
								if(this.patternList[i][j-1]===1)
								{
								draw = false;
								}
							}
							if(draw){
							drawCode2 +=	"this.creator.creator.creator.context.lineTo";
							}
							else
							{
							drawCode2 +=	"this.creator.creator.creator.context.moveTo";
							}
							drawCode2 += "(this.squareWidth*"+(i+1)+"+this.x,this.squareHeight*"+j+"+this.y); ";
							
							draw = true;
							if(i<(this.size-1)){
								if(this.patternList[i+1][j]===1)
								{
								draw = false;
								}
							}
							if(draw){
							drawCode2 +=	"this.creator.creator.creator.context.lineTo";
							}
							else
							{
							drawCode2 +=	"this.creator.creator.creator.context.moveTo";
							}
							drawCode2 += "(this.squareWidth*"+(i+1)+"+this.x,this.squareHeight*"+(j+1)+"+this.y); "
							
							draw = true;
							if(j<(this.size-1)){
								if(this.patternList[i][j+1]===1)
								{
								draw = false;
								}
							}
							if(draw === true){
							drawCode2 +=	"this.creator.creator.creator.context.lineTo";
							}
							else
							{
							drawCode2 +=	"this.creator.creator.creator.context.moveTo";
							}
							drawCode2 += "(this.squareWidth*"+i+"+this.x,this.squareHeight*"+(j+1)+"+this.y); "
	
							draw = true;
							if(i>0){
								if(this.patternList[(i-1)][j]===1)
								{
								draw = false;
								}
							}
							if(draw){
							drawCode2 +=	"this.creator.creator.creator.context.lineTo";
							}
							else{
							drawCode2 +=	"this.creator.creator.creator.context.moveTo";
							}
							drawCode2 += "(this.squareWidth*"+i+"+this.x,this.squareHeight*"+j+"+this.y); "
						}
					}			
				}
			
			var addCode =		"this.creator.creator.creator.context.strokeStyle = 'rgb(0,0,0)'; "
			addCode +=			"this.creator.creator.creator.context.stroke(); "
			addCode +=			"this.creator.creator.creator.context.translate(this.x+this.squareWidth*"+this.size+"/2,this.y+this.squareHeight*"+this.size+"/2); ";			
			addCode += 			"this.creator.creator.creator.context.rotate((-this.angle * Math.PI) / 180); "
			addCode +=			"this.creator.creator.creator.context.translate(-this.x-this.squareWidth*"+this.size+"/2,-this.y-this.squareHeight*"+this.size+"/2); ";
			drawCode += addCode;
			drawCode2 += addCode;
		this.drawCode = drawCode;
		this.drawCode2 = drawCode2;
		}